﻿using System.Linq;
using Microsoft.SharePoint;

namespace RoketSolutions.SP2010.Infrostructure.Common.Extensions
{
    public static class SpFileCollection
    {
        public static bool Contains(this SPFileCollection files, string fileName)
        {
            return files.Cast<SPFile>().Any(file => file.Name.EqualByContent(fileName));
        }

        public static SPFile GetFile(this SPFileCollection files, string fileName)
        {
            return files.Contains(fileName)
                       ? files.Cast<SPFile>().First(file => file.Name.EqualByContent(fileName))
                       : null;
        }
    }
}